package com.th.supcom.pds.auditprescription.client.mvc;

import net.carefx.framework.container.client.page.PageContext;

import com.extjs.gxt.ui.client.Style.HideMode;
import com.extjs.gxt.ui.client.mvc.AppEvent;
import com.extjs.gxt.ui.client.mvc.Controller;
import com.extjs.gxt.ui.client.mvc.View;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.th.supcom.pds.auditprescription.client.common.AuditPrescripInfoModuleEvents;
import com.th.supcom.pds.auditprescription.client.widget.AuditPrescripMainPanel;
import com.th.supcom.pds.common.client.model.PdsSupplyModel;

/**
 * 处方审核视图.
 * 
 * @author yzhang 处方审核信息.
 */
public class AuditPrescripView extends View
{

    /** 公司版权信息. */
    public static final String copyright = "Copyright 2014, TH Supcom Corporation";

    /** 提交路径. */
    public static final String SCC_BRANCH = "$URL$";

    /** 提交日期. */
    public static final String SCC_LAST_MODIFICATION_DATE = "$Date$";

    /** 最终修改人员. */
    public static final String SCC_LAST_MODIFIER_NAME = "$Author$";

    /** 最终版本号. */
    public static final String SCC_REVISION = "$Revision$";

    /** 主窗口容器. */

    private AuditPrescripMainPanel m_AuditPrescripMainPanel;

    /**
     * @param controller
     */
    public AuditPrescripView (final Controller controller)
    {
        super (controller);
    }

    @Override
    protected void handleEvent (final AppEvent event)
    {
        if (AuditPrescripInfoModuleEvents.UI_INIT.equals (event.getType ()))
        {
            final PageContext context = event.getData ();
            this.initUI (context);
        }
        else if (AuditPrescripInfoModuleEvents.QUERY_INFO.equals (event.getType ()))
        {
            onQueryInfo ((PdsSupplyModel) event.getData ("model"));
        }
        else if (AuditPrescripInfoModuleEvents.PRESC_PASS.equals (event.getType ()))
        {
            onPassPresc ();
        }
        else if (AuditPrescripInfoModuleEvents.PRESC_REFUSE.equals (event.getType ()))
        {
            onRefusePresc ();
        }
        else if (AuditPrescripInfoModuleEvents.CLEAR_INFO.equals (event.getType ()))
        {
            onClearInfo ();
        }
    }

    /**
     * 初始化容器面板.
     * 
     * @param context
     */
    private void initUI (final PageContext context)
    {
        final LayoutContainer mainLayoutContainer = context.getContainer ();
        mainLayoutContainer.setLayout (new FitLayout ());
        mainLayoutContainer.setHideMode (HideMode.OFFSETS);
        m_AuditPrescripMainPanel = new AuditPrescripMainPanel ();
        mainLayoutContainer.add (m_AuditPrescripMainPanel);

    }

    private void onClearInfo ()
    {
        m_AuditPrescripMainPanel.clearInfo (true);
    }

    private void onPassPresc ()
    {
        m_AuditPrescripMainPanel.passPresc ();
    }

    private void onQueryInfo (final PdsSupplyModel model)
    {
        m_AuditPrescripMainPanel.queryInfo (model);
    }

    private void onRefusePresc ()
    {
        m_AuditPrescripMainPanel.refusePresc ();
    }
}